import { createApp } from 'vue';

import mitt from 'mitt';
import useClipboard from 'vue-clipboard3';
import { message, Modal } from 'ant-design-vue';

import App from './App.vue';

import router from './router';
import store from './store';
import axios from './libs/axios-helper';
import components from './components/index';

import '@/assets/less/site.less';

/**
 * 显示固定位数的数字。
 * @param {Number} bits
 * @returns {String} 固定位数的数字(不足的在左侧补零)。
 */
 Number.prototype.leftPad = function (bits, padChar) {
  padChar = padChar || '0';

  var bitsArray = [padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar, padChar];
  var length = this.toFixed(0).toString().length;

  return (length >= bits) ? this : bitsArray.slice(0, bits - length).join('') + this;
};

const emitter = mitt();
const { toClipboard } = useClipboard();

const app = createApp(App);

app.config.globalProperties.$modal = Modal;
app.config.globalProperties.$message = message;
app.config.globalProperties.$eventBus = emitter;
app.config.globalProperties.$copyText = toClipboard;

app.provide('$modal', Modal);
app.provide('$message', message);
app.provide('$eventBus', emitter);
app.provide('$copyText', toClipboard);

app
  .use(store)
  .use(router)
  .use(axios)
  .use(components)
  .mount('#app');
